﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace TestStudent
{
    [TestClass]
    public class CourseTest
    {
        [TestMethod]
        public void AddStudentTest()
        {
            string name = string.Empty;
            Student student = new Student("Suicider", 11111);
            Course target = new Course(name);
            target.AddStudent(student);
            if (!target.Contains(student))
            {
                Assert.Fail("Student not successfully added"); 
            }
        }

        [TestMethod]
        public void AddStudentTestDifferentFacultyNumbers()
        {
            string name = string.Empty;
            Student firstStudent = new Student("Suicider", 11111);
            Student secondStudent = new Student("Suicider", 11112);
            Course target = new Course(name);
            target.AddStudent(firstStudent);
            target.AddStudent(secondStudent);
            Assert.AreEqual(2, target.Count);
        }

        [TestMethod]
        public void AddStudentTestDifferentNames()
        {
            string name = string.Empty;
            Student firstStudent = new Student("Suicider", 11111);
            Student secondStudent = new Student("Ahmed", 11111);
            Course target = new Course(name);
            target.AddStudent(firstStudent);
            target.AddStudent(secondStudent);
            Assert.AreEqual(2, target.Count);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddStudentTestDuplicate()
        {
            string name = string.Empty;
            Student firstStudent = new Student("Suicider", 11111);
            Student secondStudent = new Student("Suicider", 11111);
            Course target = new Course(name);
            target.AddStudent(firstStudent);
            target.AddStudent(secondStudent);
        }

        [TestMethod]
        public void CountTestMaximumReached()
        {
            string name = string.Empty;
            Course target = new Course(name);
            string studentName = "DummyName";
            int startFacultyNumber = 10000;
            for (int i = 0; i < 30; i++)
            {
                Student student = new Student(studentName, startFacultyNumber + i);
                target.AddStudent(student);
            }
        }

        [TestMethod]
        [ExpectedException(typeof(OverflowException))]
        public void CountTestOverflow()
        {
            string name = string.Empty;
            Course target = new Course(name);
            string studentName = "DummyName";
            int startFacultyNumber = 10000;
            for (int i = 0; i < 31; i++)
            {
                Student student = new Student(studentName, startFacultyNumber + i);
                target.AddStudent(student);
            }
        }

        [TestMethod]
        public void DeleteStudentTest()
        {
            string name = string.Empty;
            Student student = new Student("Suicider", 11111);
            Course target = new Course(name);
            target.AddStudent(student);
            target.DeleteStudent(student);
            if (target.Contains(student))
            {
                Assert.Fail("Student was not deleted");
            }
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void DeleteStudentTestDifferentFacultyNymber()
        {
            string name = string.Empty;
            Student student = new Student("Suicider", 11111);
            Course target = new Course(name);
            Student studentToBeDeleted = new Student("Suicider", 11112);
            target.AddStudent(student);
            target.DeleteStudent(studentToBeDeleted);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void DeleteStudentTestDifferentName()
        {
            string name = string.Empty;
            Student student = new Student("Suicider", 11111);
            Course target = new Course(name);
            Student studentToBeDeleted = new Student("Ahmed", 11111);
            target.AddStudent(student);
            target.DeleteStudent(studentToBeDeleted);
        }
    }
}